package o;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.agreement.api.ui.ITermsActivityProtocol;
import java.lang.ref.WeakReference;
import o.axa.c;
import o.axa.h;

public class axp {
    private static final Object ʻ = new Object();
    private static axp ˏ = null;
    private static boolean ॱ = true;
    private axu ˊ;
    private axs ˋ;
    private WeakReference<Activity> ˎ;
    private WeakReference<Activity> ॱॱ;

    static class b implements cks {
        private boolean ˊ;
        private axt ˋ;
        private CheckBox ˎ;
        private WeakReference<axp> ˏ;

        b(axp o_axp, axt o_axt, boolean z, CheckBox checkBox) {
            this.ˋ = o_axt;
            this.ˊ = z;
            this.ˏ = new WeakReference(o_axp);
            this.ˎ = checkBox;
        }

        public void enableNetworking() {
            axp o_axp = (axp) this.ˏ.get();
            if (o_axp != null) {
                o_axp.ˎ(this.ˊ);
            }
            this.ˋ.ˏ();
            if (this.ˎ != null) {
                axg.ˏ().ˏ(this.ˎ.isChecked());
            }
            axp.ˏ(true);
        }

        public void upgrade() {
            axp o_axp = (axp) this.ˏ.get();
            if (o_axp != null) {
                o_axp.ˎ(this.ˊ);
            }
            this.ˋ.ॱ();
            axp.ˏ(true);
        }

        public void ˋ() {
            axp o_axp = (axp) this.ˏ.get();
            if (o_axp != null) {
                o_axp.ˎ(this.ˊ);
            }
        }
    }

    static class e implements OnCheckedChangeListener {
        private e() {
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            axp.ˏ(z);
        }
    }

    private static boolean ˏ() {
        return ॱ;
    }

    private static void ˏ(boolean z) {
        ॱ = z;
    }

    public static axp ॱ() {
        axp o_axp;
        synchronized (ʻ) {
            if (ˏ == null) {
                ˏ = new axp();
            }
            o_axp = ˏ;
        }
        return o_axp;
    }

    private void ˊ(axs o_axs, WeakReference<Activity> weakReference) {
        Object obj = weakReference != null ? (Activity) weakReference.get() : null;
        if (o_axs != null && obj != null) {
            awg.ˎ.ˋ("ProtocolDialog", "dismissOldDialog from:" + obj);
            o_axs.ॱ();
            if (o_axs.ˊ != null) {
                o_axs.ˊ.upgrade();
            }
        }
    }

    public void ˋ(String str, Activity activity, @Nullable ITermsActivityProtocol iTermsActivityProtocol, axx o_axx, axt o_axt) {
        if (ays.ˎ() || axe.ˏ(str)) {
            awg.ˎ.ˋ("ProtocolDialog", "showProtocol");
            ˊ(activity, iTermsActivityProtocol, o_axx, o_axt);
            return;
        }
        awg.ˎ.ˋ("ProtocolDialog", "showOverseaProtocol");
        ˋ(activity, iTermsActivityProtocol, o_axx, o_axt);
    }

    private axs ˊ(Activity activity, @Nullable ITermsActivityProtocol iTermsActivityProtocol, axx o_axx, axt o_axt) {
        CheckBox checkBox;
        awg.ˎ.ˋ("ProtocolDialog", "showProtocol dialog from: " + activity);
        ayw.ˋ(activity, "LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES");
        ˊ(this.ˋ, this.ˎ);
        this.ˋ = axs.ˎ(activity, iTermsActivityProtocol);
        this.ˎ = new WeakReference(activity);
        awx ʻ = axg.ˏ().ʻ();
        CheckBox ˋ = this.ˋ.ˋ();
        if (ˋ != null) {
            ˋ.setTextColor(activity.getResources().getColor(c.ˋ));
            ˋ.setTypeface(Typeface.create(activity.getString(h.ʻ), 0));
            ˋ.setTextSize(0, activity.getResources().getDimension(o.axa.e.ˊ));
            ˋ.setChecked(ˏ());
            ˋ.setOnCheckedChangeListener(new e());
            ˋ.setText(ʻ.ॱˊ());
        }
        String ˎ = ʻ.ˎ();
        String ॱ = ʻ.ॱ();
        String ˋ2 = ʻ.ˋ();
        awg.ˎ.ˎ("ProtocolDialog", " userTitle ; " + ˎ + "  privateTitle: " + ॱ + "  content: " + ˋ2);
        if ((iTermsActivityProtocol != null ? iTermsActivityProtocol.getViewType() : 0) == 1 && ˋ != null) {
            ˋ.setVisibility(8);
            ˋ.setChecked(false);
        }
        TextView ˎ2 = this.ˋ.ˎ();
        if (axe.ˏ(ays.ˊ())) {
            if (ˋ != null) {
                ˋ.setVisibility(8);
                checkBox = null;
            } else {
                checkBox = ˋ;
            }
            ˎ((Context) activity, ˎ2, new axw(ˎ, ॱ), ʻ);
        } else {
            ˊ(activity, ˎ2, ˋ2, new axw(ˎ, ॱ), ʻ);
            checkBox = ˋ;
        }
        this.ˋ.ˊ(new b(this, o_axt, false, checkBox));
        return this.ˋ;
    }

    private void ˊ(axu o_axu, WeakReference<Activity> weakReference) {
        Object obj = weakReference != null ? (Activity) weakReference.get() : null;
        if (o_axu != null && obj != null) {
            awg.ˎ.ˋ("ProtocolDialog", "dismissOldOverseaDialog from:" + obj);
            o_axu.ˎ();
            if (o_axu.ˊ != null) {
                o_axu.ˊ.upgrade();
            }
        }
    }

    private axu ˋ(Activity activity, @Nullable ITermsActivityProtocol iTermsActivityProtocol, axx o_axx, axt o_axt) {
        awg.ˎ.ˋ("ProtocolDialog", "showOverseaProtocol dialog from:" + activity);
        ˊ(this.ˊ, this.ॱॱ);
        this.ˊ = axu.ॱ(activity, iTermsActivityProtocol, o_axx);
        this.ॱॱ = new WeakReference(activity);
        this.ˊ.ˎ(new b(this, o_axt, true, null));
        return this.ˊ;
    }

    public void ॱ(Activity activity, String str) {
        if (ays.ˎ() || axe.ˏ(str)) {
            awg.ˎ.ˋ("ProtocolDialog", "dismissProtocol");
            ˎ(activity);
            return;
        }
        awg.ˎ.ˋ("ProtocolDialog", "dismissOverseaProtocol");
        ˊ(activity);
    }

    private void ˎ(Activity activity) {
        Activity activity2 = this.ˎ != null ? (Activity) this.ˎ.get() : null;
        awg.ˎ.ˋ("ProtocolDialog", "dismiss from:" + activity + " dialog owner Activity:" + activity2);
        if (this.ˋ != null && activity2 == activity) {
            this.ˋ.ॱ();
            ˎ(false);
        }
    }

    private void ˊ(Activity activity) {
        Activity activity2 = this.ॱॱ != null ? (Activity) this.ॱॱ.get() : null;
        awg.ˎ.ˋ("ProtocolDialog", "dismissOversea from:" + activity + " dialog owner Activity:" + activity2);
        if (this.ˊ != null && activity2 == activity) {
            this.ˊ.ˎ();
            ˎ(true);
        }
    }

    private void ˎ(boolean z) {
        if (z) {
            this.ˊ = null;
            this.ॱॱ = null;
            return;
        }
        this.ˋ = null;
        this.ˎ = null;
    }

    private void ˊ(Context context, TextView textView, String str, axw o_axw, awx o_awx) {
        if (!dof.ˋ(str)) {
            SpannableString spannableString = new SpannableString(str);
            ˏ(context, spannableString, textView, str, o_axw);
            if (ays.ˎ()) {
                ˎ(context, spannableString, str, o_awx.ʻ());
                ˎ(context, spannableString, str, o_awx.ˋॱ());
                ˋ(context, spannableString, textView, str, o_axw);
            }
            textView.setText(spannableString);
            textView.setMovementMethod(new ckl.c());
            textView.setHighlightColor(context.getResources().getColor(c.ˊ));
        }
    }

    private void ˎ(Context context, TextView textView, axw o_axw, awx o_awx) {
        String ˋ = o_awx.ˋ();
        String ˏॱ = o_awx.ˏॱ();
        if (!dof.ˋ(ˋ) && !dof.ˋ(ˏॱ)) {
            String str = ˋ + "\n" + ˏॱ;
            SpannableString spannableString = new SpannableString(str);
            ˎ(context, spannableString, str, o_awx.ʻ());
            ˎ(context, spannableString, str, o_awx.ˋॱ());
            ˏ(context, spannableString, textView, str, o_axw);
            ˋ(context, spannableString, textView, str, o_axw);
            textView.setMovementMethod(new ckl.c());
            textView.setHighlightColor(context.getResources().getColor(c.ˊ));
            textView.setText(spannableString);
        }
    }

    private void ˎ(Context context, SpannableString spannableString, String str, String str2) {
        if (dof.ˋ(str)) {
            awg.ˎ.ˏ("ProtocolDialog", "content is blank");
        } else if (dof.ˋ(str2)) {
            awg.ˎ.ˏ("ProtocolDialog", "keyStr is blank");
        } else {
            int lastIndexOf = str.lastIndexOf(str2);
            if (lastIndexOf != -1) {
                int length = str2.length() + lastIndexOf;
                spannableString.setSpan(new StyleSpan(1), lastIndexOf, length, 33);
                spannableString.setSpan(new ForegroundColorSpan(context.getResources().getColor(c.ˋ)), lastIndexOf, length, 33);
            }
        }
    }

    public void ˋ(Context context, TextView textView, String str, axw o_axw) {
        String ॱॱ = dof.ॱॱ(str);
        SpannableString spannableString = new SpannableString(ॱॱ);
        ˏ(context, spannableString, textView, ॱॱ, o_axw);
        if (ays.ˎ()) {
            ˋ(context, spannableString, textView, ॱॱ, o_axw);
        } else {
            ॱ(context, spannableString, textView, ॱॱ, o_axw.ˏ(), false);
        }
        textView.setText(spannableString);
        textView.setMovementMethod(new ckl.c());
        textView.setHighlightColor(context.getResources().getColor(c.ˊ));
    }

    private void ˏ(Context context, SpannableString spannableString, TextView textView, String str, axw o_axw) {
        o.ayo.e eVar = new o.ayo.e(context, 1, false);
        ayr.ॱ(context, spannableString, textView, str, o_axw.ˋ(), eVar.ˎ());
    }

    private void ˋ(Context context, SpannableString spannableString, TextView textView, String str, axw o_axw) {
        o.ayo.e eVar = new o.ayo.e(context, 2, false);
        ayr.ॱ(context, spannableString, textView, str, o_axw.ˏ(), eVar.ˎ());
    }

    private void ॱ(Context context, SpannableString spannableString, TextView textView, String str, String str2, boolean z) {
        ayr.ॱ(context, spannableString, textView, str, str2, new o.ayo.e(context, 2, z).ˎ());
    }
}
